home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 490 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: qcd.lanl.gov!tanmoy
  2. From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: char* string problem
  5. Date: 5 Jan 1996 20:38:44 GMT
  6. Organization: Los Alamos National Laboratory
  7. Distribution: world
  8. Message-ID: <4ck28k$mv7@newshost.lanl.gov>
  9. References: <4ci7gu$68r@cloner3.netcom.com> <820846052snz@intellic.demon.co.uk>
  10. NNTP-Posting-Host: qcd.lanl.gov
  11.  
  12. In article <820846052snz@intellic.demon.co.uk>, Chris Trueman
  13. <truemanc@intellic.demon.co.uk> writes: 
  14. |> In article <4ci7gu$68r@cloner3.netcom.com>
  15. |>            tstevens@ix.netcom.com "Edward Stevens " writes:
  16. <snip>
  17. |> >char* Aprefix = " -A";
  18. <snip>
  19. |> >the_args[0] = strcat(Aprefix,the_args[0]);
  20. |> 
  21. |> Your problem is that the_args[0] is being set to the address of
  22. |> Aprefix which points to three (3) blocks of memory. By executing the
  23. |> strcat you are overwriting memory you have not already allocated.
  24.  
  25. More importantly, string literals are _constants_. Trying to modify them in
  26. _any_ way leads to undefined behaviour (when not a diagnosable error, that
  27. is). strcat tries to modify the first '\0' which forms part of the string: in
  28. this case the fourth character of the string literal. (Yes, sizeof " -A" is 4
  29. not 3).
  30.  
  31. Cheers
  32. Tanmoy
  33. -- 
  34. tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
  35. Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
  36. Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
  37. <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
  38. internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
  39. fax: 1 (505) 665 3003   voice: 1 (505) 665 4733    [ Home: 1 (505) 662 5596 ]
  40.